class Frontend::UsersController < Frontend::BaseController
  before_action :logged_in?, except: [:new, :create]
  before_action :set_user, only: [:show, :edit, :update]

  def show
    # @user = User.find(params[:id])
  end

  def edit

  end

  def update
  end

  def new
    @user = User.new
    render layout: "backend_login"
  end

  def create
    @user = User.new(user_params)
    if !verify_rucaptcha?
      flash[:alert] = '验证码错误'
      render(action: :new, layout: "backend_login") and return
    end
    if @user.save
      set_current_user @user
      flash[:success] = "注册成功!"
      redirect_to frontend_root_path
    else
      flash[:error] = "注册失败！"
      render(action: :new, layout: "backend_login") and return
    end
  end

  private

  def user_params
    params.require(:user).permit!
  end


  def set_user
    @user = User.find(params[:id])
  end
end
